<?php
/**
 * Created by PhpStorm.
 * User: plume
 * Date: 2017/11/14
 * Time: 15:45
 */

namespace App\Http\Controllers;

use App\Models\Apply;
use Illuminate\Support\Facades\Auth;

class ApplyController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    public function apply(){
        $user = Auth::user();
        $apply = Apply::where('user_id', $user->id)->where('created_at', '>', date('Y-m-d H:i:s',strtotime('-1 day')))->first();
        if(empty($apply)){
            $new_apply = new Apply();
            $new_apply->user_id = $user->id;
            $new_apply->save();
            return ['code'=>0, 'msg'=>'success'];
        }else{
            return ['code'=>1, 'msg'=>'has applied'];
        }
    }
}